import React, { useEffect, useState } from 'react';
import { useHistory } from "react-router-dom";
import {
  List, DatePicker, Picker, Modal, Button,
  InputItem, TextareaItem, Toast, Flex, Switch,Drawer, Card
} from 'antd-mobile';
import Btn from "../../../components/btn/Btn";
import './appointmentRecordEdit2.less';
import UserMsg from "../../outUser/userMsg/UserMsg";
import http from "../../../model/http";
import { dateFormat, sendMsg } from "../../../model/code";
import { Calendar } from 'react-h5-calendar'; 

const Item = List.Item,
  _now = new Date(),
  tomorrow = new Date(_now.getTime() + 24 * 3600 * 1000);

function Edit2() {
  const history = useHistory(), { item, outUser } = history.location.state;
  console.log(item)
  // 仪器列表
  const [instrumentList, setInstrumentList] = useState([]);
  const [instrument, setInstrument] = useState([-1]);
  // 麻醉类型
  const [hocustList, setHocusList] = useState([{ label: '全麻', value: 2 }, { label: '局麻', value: 1 }]);
  const [hocus, setHocus] = useState([-1]);

  // 医生列表
  const [doctorList, setDoctorList] = useState([]);
  const [doctor, setDoctor] = useState([-1]);
  const [doctor2, setDoctor2] = useState([-1]);

  // 项目次数
  const [count, setCount] = useState('1')
  const nowTimeStamp = new Date();
  //治疗日期
  const [date, setDate] = useState("");
  const [time2, setTime2] = useState("");
  const [time3, setTime3] = useState("");

  
 //自行填写时间点
 const [timeView1, setTimeView1] = useState();
 const [timeView2, setTimeView2] = useState();


  // 治疗时长
  const [time, setTime] = useState('2');
  // 治疗时长-失去焦点更新
  const [timeBlur, setTimeBlur] = useState(true);
  // 治疗时间
  const [time4, setTime4] = useState(0);
  // 时间段
  const [time5, setTime5] = useState(['', '']);
  // 时间段列表
  const [timeList, setTimeList] = useState([]);
  // 时间段弹窗
  const [time1, setTime1] = useState(false);
  // 单个可选时间段
  const [timeIdx, setTimeIdx] = useState({ _show: false });
  // 备注
  const [mark, setMark] = useState('')
  // 是否已检
  const [switchIscheck, setSwitchIscheck] = useState(false)
  // 是否缴费
  const [switchIsmoney, setSwitchIsmoney] = useState(false)

  // 治疗时长
  const [bookingTime, setBookingTime] = useState(0)
  // 选择治疗医生之后显示列表
  const [doctorDayShow, setDoctorDayShow] = useState(false)

  // 遮罩层
  const [doctorDayListShow, setDoctorDayListShow] = useState(false)

  // 遮罩层里面的日期 默认今日 
  const [dateValue, setDateValue] = useState(nowTimeStamp)
  const [doctorListData, setDoctorListData] = useState([])
  const [doctorTimeTitle,setDoctorTimeTitle] = useState('')

  // 时间列表
  const [timeDataList,setTimeDataList] = useState([])
  const [timeDataListShow, setTimeDataListShow] = useState(false)

  const [active,setActive] = useState(-1)

  // 当日轮牌
  const [dailyRotation, setDailyRotation] = useState(false)
  // 执行科室
  const [departmentList, setDepartmentList] = useState([
    {label:'整形中心',value:'DE0011'},
    {label:'皮肤中心',value:'DE0012'},
    {label:'无创中心',value:'DE0013'},
    {label:'口腔中心',value:'DE0014'},
    {label:'植发中心',value:'DE0015'}, 
  ])
  const [department, setDepartment] = useState([-1])
  const [doctorShow, setDoctorShow] = useState(true)
  const [doctorName, setDoctorName] = useState('')

  useEffect(async () => {

    // if (!doctorList.length) {
    //   // const _doctor = await http.post('/customer/doctorList');
    //   http.get('/expert/list', {
    //     hosId: window.hos.hosId,
    //   }).then(res => {
    //     if (res.code == '0') {
    //       setDoctorList(res.data)
    //     }
    //   })
    // }

    // 赋值  
    
    sessionStorage.setItem('detailsData',JSON.stringify(item))
    // 赋值 
    setHocus([Number(item.hocusType)])
    setSwitchIscheck(item.is_check=="0"?false:true)
    setSwitchIsmoney(item.is_money=="0"?false:true) 
    let expert_infoData = item.expert_info

    // 仪器列表 
    const instrumentListData = await http.post('/scheduler/getDeviceList',{
      deptId:'DE0012',
    })
    let newLabel = instrumentListData.data.map(item => {
      return {
        label: item.equipment_name,
        value: item.tgb_armarium_id
      }
    })
    setInstrumentList(newLabel)
    
    

    setDepartment([expert_infoData[0].deptGroupId])
    // 获取医生接口
    const result = await http.post('/manager/getDeptPersonList',{
      deptId: expert_infoData[0].deptGroupId,
      userType:3
    }) 
    let newData = result.data.map(item => {
      return {
        label: item.name,
        value: item.erp_id
      }
    })
    setDoctorList(newData)
    
    if(item.is_auto=='1'){
      setDailyRotation(true)
      setDoctorShow(false) 
      setDate(item.sdate) 
      setDoctor([expert_infoData[0].expert_id])
      setDoctorName(expert_infoData[0].expert_name)
    }else{
      

      setDoctor(expert_infoData[0].deptGroupId != '' && expert_infoData[0].expert_id !='' && expert_infoData[0].expert_name !='' && Object.getOwnPropertyNames(expert_infoData[0]).length > 0 ? [`${expert_infoData[0].expert_id}`]:[-1])  

      setDoctor2(expert_infoData.length>1 && Object.getOwnPropertyNames(expert_infoData[1]).length > 0?[`${expert_infoData[1].expert_id}`]:[-1])
      
      setDate(new Date(item.sdate)) 
      setDailyRotation(item.is_auto=='1'?true:false)
      
    }
    setTime2(changeDateAndriodIos(`${item.sdate} ${item.begintime}`))   
    setTime3(changeDateAndriodIos(`${item.sdate} ${item.endtime!=''?item.endtime:item.begintime}`))
    setBookingTime(item.estimate_time !='' ? item.estimate_time : '0' )


    if(expert_infoData[0].deptGroupId !="DE0011"){
      setTimeView1(changeDateAndriodIos(`${item.sdate} ${item.begintime}`))   
      setTimeView2(changeDateAndriodIos(`${item.sdate} ${item.endtime!=''?item.endtime:item.begintime}`))
    }

     
    setMark(item.memo)
    



    // eslint-disable-next-line
  }, [])

  const showModal = () => {
    if (instrument[0] < 0) { Toast.fail('请选择仪器'); return };
    if (doctor[0] < 0) { Toast.fail('请选择医生'); return };
    if (time < 0) { Toast.fail('请输入治疗时长'); return };
    setTime1(true);

  }
  const changeDateAndriodIos = (value) => {
    let arr = value.split(/[- : -]/);
    const date = new Date(arr[0], arr[1] - 1, arr[2], arr[3], arr[4], arr[5]?arr[5]:'00');
    return date;
  }

  const showSelectTime = item => {
    if (!item.isBlank) return;
    setTimeIdx({ minDate: item._start, maxDate: item._end, show: true, _show: true });
  }
  const selectTime = _date => {
    setTimeIdx({ _show: false }); setTime1(false);
    if (!_date) return;
    setTime5([dateFormat(_date, 'hh:mm'), dateFormat(new Date(_date.getTime() + time * 60 * 1000), 'hh:mm')]);
  }

  const submit = () => {
    // history.push('/yuyue/notice2');
    // if(instrument[0]<0){Toast.fail('请选择仪器');return};
    // if(department == 'DE0012'){
    //   if(instrument[0]=== -1){Toast.fail('请选择仪器');return};
    // }
    if (doctor[0] < 0) { Toast.fail('请选择医生'); return };
    if (hocus[0] < 0 && department =="DE0011") { Toast.fail('请选择麻醉类型'); return }
    if(bookingTime == 0  && department =="DE0011") {Toast.fail('请选择治疗时间'); return}

    if(department !='DE0011' && (  !timeView1  && !timeView2 ) ){ Toast.fail('请选择开始时间或结束时间'); return  }
    // if(!time5[0]){Toast.fail('请选择时间段');return};

    let frequencyData = sessionStorage.getItem('frequencyData') ? JSON.parse(sessionStorage.getItem('frequencyData')) : []
    for (let i in frequencyData) {
      frequencyData[i].times = frequencyData[i].thiscs
      frequencyData[i].itemid = frequencyData[i].trid
    }
    let newDataJson = frequencyData.filter(item => {
      return item.thiscs != undefined && item.thiscs != null && item.thiscs != 0
    })
    if (newDataJson.length < 1) { 
      Toast.fail('请先选择治疗项目');
      setTimeout(() => {
        history.go(-1)
      }, 1000);
      return 
    }
    console.log('newDataJson:', newDataJson)
    console.log('doctor2:', doctor2)
    Modal.alert('提示', '确认预约', [
      { text: '取消' },
      {
        text: '预约', onPress: async () => {
          const order = await http.post('/customer/addCure', {
            customerCrmId: item.customerInfo.baseInfo[0].customerCrmId,   // 顾客id
            customerCrmName: item.customerInfo.baseInfo[0].customerName,  // 顾客姓名
            expertId: doctor[0],
            expertId2: doctor2[0] != -1 && doctor2.length > 0 ? doctor2[0] : '',
            deptId: department,
            instrumentId: instrument[0] !== -1 ? instrument[0] : '',
            // instrumentId:'',
            schedulerDate: dailyRotation?date:dateFormat(date, 'yyyy-MM-dd'),
            beginTime:department=="DE0011"?
                  dateFormat(time2, 'hh:mm:ss'):
                  dateFormat(timeView1, 'hh:mm')+":00",

            endTime:department=="DE0011"? 
                    dateFormat(time3, 'hh:mm:ss'):
                    dateFormat(timeView1, 'hh:mm')+":00",
            memo: mark,
            ischeck: switchIscheck ? 1 : 0,
            ismoney: switchIsmoney ? 1 : 0,
            crdId: item.crdId,
            // hocusType: hocus[0] < 0 ? '' : hocus,
            hocusType:department =='DE0011' ? hocus :[-1],
            times: count > 0 ? count : 1,
            estimateTime: bookingTime,
            datajson: JSON.stringify(newDataJson),
            srid: item.srid,
            is_auto: dailyRotation?1:0
          });

          console.log('window._user:', window._user)
          console.log('item:', item)
          // const link = `${window.location.origin}/outUser/yuyue2?hosId=${window._user.hosId}&crmId=${outUser.customerCrmId}&orderId=${order.schedulerId}`;
          // sendMsg(link,'预约治疗','待确认');
          
          if(order.code == 0){
            Toast.success(order.msg) 
            setTimeout(() => {
              history.push('/user/home')
            }, 500);
          }else{
            Toast.fail(order.msg) 
          }

          

          console.log(order);
        }
      },
    ])
  }
  const showhtml = (htmlString) => {
    var html = { __html: htmlString };
    return <div dangerouslySetInnerHTML={html}></div>;
  }

  // 返回上一步
  const returnNextStep = () => {
    history.push('/yuyue/appointmentRecord', {
      outUser: outUser,
      item: item,
      historyGo: '1'
    });
  }

  // 手术时长 请求
  const getDurationFunc = async(d,hoc,v=doctor) => {
    
    const timeDataList = await http.post('/scheduler/checkScheduleTimeAuto',{
      expertId: v[0],
      sch_date: d,
      hocusType: hoc,
      customerCrmId: outUser.customerCrmId,   // 顾客id
      deptId: department[0]
    })
    if(timeDataList.code == 0){
      setDate(new Date(d)) 
      setTimeDataListShow(true)
      setTimeDataList(timeDataList.data)
      setTime2(new Date(new Date().toLocaleDateString()))
      setTime3(new Date(new Date().toLocaleDateString()))
      setBookingTime(0)
      setActive(-1)
    }else{
      Toast.fail(timeDataList.msg);
    }
  }

  // 通过点击日期去获取手术时长
  const getDuration = async (d) => {
    if (doctor[0] < 0 ) { Toast.fail('请先选择治疗医生'); return };
    if (hocus[0] < 0 && department=="DE0011") { Toast.fail('请先选择麻醉类型'); return }; 
    
    

    getDurationFunc(dateFormat(d, 'yyyy-MM-dd'), hocus) 
  }
  
  // 通过点击麻醉类型获取时长
  const getDuration2 = async (v) => { 
    setHocus(v)
    if(dailyRotation == true){   
      getTodayQueueDataFunc(department[0] , v)
    }
    if(doctor[0] < 0 || date == ''){
      return false;
    }
    getDurationFunc(dateFormat(date, 'yyyy-MM-dd'),v)
    
  }

  // doctorTimeList
  const doctorTimeListFunc = async (doc, t) => {
    const getDoctorDayList = await http.post('/scheduler/getExpertTrTime', {
      expertId: doc,
      sch_date: t,
    })
    if (getDoctorDayList.code == '0') {
      setDoctorListData(getDoctorDayList.data)
      setDoctorTimeTitle(getDoctorDayList.pbname) 
    }
  }

  // 选择治疗医生之后弹出框
  const getDoctorDay = async (v) => {
    // 赋值
    setDoctor(v)
    // 显示
    setDoctorDayShow(true)
    doctorTimeListFunc(v[0], dateFormat(nowTimeStamp, 'yyyy-MM-dd'))
    if(date!=''){
      getDurationFunc(dateFormat(date, 'yyyy-MM-dd'), hocus, v)     
    }
  }


  // 查看手术弹框
  const operationSearch = () => {
    setDoctorDayListShow(true)

    document.body.addEventListener("touchmove", window.scroll, { passive: false });
    document.body.style.overflow = 'hidden';
  }

  // 右边弹框
  const onOpenChange = () => {
    setDoctorDayListShow(!doctorDayListShow)
    // 弹框关闭的时候 恢复body 滚动条
    if (doctorDayListShow == true) {
      //添加事件监听时添加了passive参数，在ios9中移除事件监听也需要加此参数
      document.body.removeEventListener('touchmove', window.scroll, { passive: true });
      document.body.style.overflow = 'auto';
    }
  }

  // 点击弹框里面的日期
  const onDateClick = (d) => {
    setDateValue(dateFormat(d.$d, 'yyyy-MM-dd'))
    doctorTimeListFunc(doctor[0], dateFormat(d.$d, 'yyyy-MM-dd'))
  }

  // 点击按钮渲染时间
  const timeBtnClick = (value,index) => {
    console.log(value)
    setTime2(changeDateAndriodIos(`${dateFormat(date, 'yyyy-MM-dd')} ${value.begin}`))
    setTime3(changeDateAndriodIos(`${dateFormat(date, 'yyyy-MM-dd')} ${value.end}`))
    let time2Num = new Date((`${dateFormat(date, 'yyyy-MM-dd')} ${value.begin}`).replace(/-/g, "/")).getTime()
    let time3Num = new Date((`${dateFormat(date, 'yyyy-MM-dd')} ${value.end}`).replace(/-/g, "/")).getTime() 
    setBookingTime(new Date(Number(time3Num) - Number(time2Num))/(1000*60))

    setActive(index)
  }
 

   // 当日轮排
  const rotationChange = async () => {
    if (hocus[0] < 0) { Toast.fail('请先选择麻醉类型'); return }; 
    if (department[0] < 0) { Toast.fail('请先选择执行科室'); return };
    setTimeDataListShow(false)
    setDoctorDayShow(false)
    setDailyRotation(!dailyRotation)
    if(!dailyRotation == true){
      console.log('触发')
      console.log(hocus) 

      getTodayQueueDataFunc(department[0])
      
    }else{ 
      console.log('触发')
      setDoctorShow(true)
      const details = JSON.parse(sessionStorage.getItem('detailsData'))
      setDate(new Date(details.sdate))  
      // 赋值 
      setHocus([Number(details.hocusType)])
      setSwitchIscheck(details.is_check=="0"?false:true)
      setSwitchIsmoney(details.is_money=="0"?false:true)
      
      const expert_infoData = details.expert_info
      
      
 
      setDepartment([expert_infoData[0].deptGroupId])

      if(expert_infoData[0].deptGroupId == 'DE0012'){
        // 麻醉类型
        setHocusList([{ label: '表麻', value: 3 }, { label: '局麻', value: 1 }]); 
      }else{
        setHocusList([{ label: '全麻', value: 2 }, { label: '局麻', value: 1 }]); 
      }
      // 获取医生接口
      const result = await http.post('/manager/getDeptPersonList',{
        deptId: expert_infoData[0].deptGroupId,
        userType:3
      }) 
      let newData = result.data.map(item => {
        return {
          label: item.name,
          value: item.erp_id
        }
      })
      setDoctorList(newData)
      
      setDoctor(expert_infoData[0].deptGroupId != '' && expert_infoData[0].expert_id !='' && expert_infoData[0].expert_name !='' && Object.getOwnPropertyNames(expert_infoData[0]).length > 0 ? [`${expert_infoData[0].expert_id}`]:[-1])  
 
      setDoctor2(expert_infoData.length>1 && Object.getOwnPropertyNames(expert_infoData[1]).length > 0?[`${expert_infoData[1].expert_id}`]:[-1])
      
      
      setTime2(changeDateAndriodIos(`${details.sdate} ${details.begintime}`))   
      setTime3(changeDateAndriodIos(`${details.sdate} ${details.endtime!=''?details.endtime:details.begintime}`))
      setBookingTime(details.estimate_time !='' ? details.estimate_time : '0' )
  

    }
  }
  // 轮排的时候调用接口 
  const getTodayQueueDataFunc = async (did,type = hocus[0]) => { 
    const result = await http.post('/expert/todayQueueData',{
      deptId: did,
      hocusType: type
    })
    console.log(result)
    setDate(result.date)
    
    setTime2(changeDateAndriodIos(`${result.date} ${result.oktime_begin!=''?result.oktime_begin:'00:00'}`)) 
    setTime3(changeDateAndriodIos(`${result.date} ${result.oktime_end!=''?result.oktime_end:'00:00'}`))
    setBookingTime(result.cure_long_minute)  
    setDoctor([result.expertId!=''?result.expertId:-1])
    setDoctorName(result.expertName!=''?result.expertName:'当日暂无轮排医生')
  }

  // 执行科室
  const getDepartmentChange = async (value) => {
    console.log(value)
    if(value == 'DE0012'){
      // 麻醉类型
      setHocusList([{ label: '表麻', value: 3 }, { label: '局麻', value: 1 }]); 
    }else{
      setHocusList([{ label: '全麻', value: 2 }, { label: '局麻', value: 1 }]); 
    }
    setHocus([-1])
    setDepartment(value)
    // http://wxwork.gzsg.cn/wxwork/manager/getDeptPersonList?hosId=1&userId=xx&managerId=1629697426248&deptId=DE0011&userType=3
    const result = await http.post('/manager/getDeptPersonList',{
      deptId:value,
      userType:3
    })
    if(result.code == 0){
      let newData = result.data.map(item => {
        return {
          label: item.name,
          value: item.erp_id
        }
      })
      setDoctorList(newData)
      setDoctor([-1])
      // 显示
      setDoctorDayShow(false)
      setDoctorShow(true)
    }

    // 如果排班不等于空
    if(dailyRotation != false){
      getTodayQueueDataFunc(value[0])
    }
  }
   

  return (
    <div className='v-yueyu-appointmentRecordEdit2'>
      <UserMsg msg={Object.getOwnPropertyNames(item).length > 0 ? item.customerInfo.baseInfo[0] : {}} />

      <List className='g-p5-10 g-bg-f g-bdrs12 g-mb10'>
        <Item wrap extra={showhtml(item.displayname)} className="edit2-treatment-items">治疗项目</Item>
        <Picker
          cols={1}
          title="执行科室"
          data={departmentList}
          value={department}
          onOk={(v) => getDepartmentChange(v)}
        >
          <Item arrow="horizontal"><Flex>执行科室  <b style={{color:'red',marginTop:'-10px'}}>*</b></Flex></Item>
        </Picker>

        {
          department =="DE0011" ?(
            <Picker data={hocustList} cols={1}
            value={hocus} onOk={v => getDuration2(v)}>
            <Item arrow="horizontal"><Flex>麻醉类型  <b style={{color:'red',marginTop:'-10px'}}>*</b></Flex></Item>
          </Picker>
          ):null
        }


       

        <Item
          extra={
            <Switch
              checked={switchIscheck}
              onChange={() => setSwitchIscheck(!switchIscheck)}
            />}
        >是否已检
        </Item>

        <Item
          extra={
            <Switch
              checked={switchIsmoney}
              onChange={() => setSwitchIsmoney(!switchIsmoney)}
            />}
        >是否缴费
        </Item>

        {department=="DE0011" ? (
            <Item
            extra={
              <Switch
                checked={dailyRotation}
                onChange={() => rotationChange()}
                color="#108ee9"
              />}
          >当日轮排
          </Item>
        ):null}


        {!dailyRotation && doctorShow ? (
          <Picker
            cols={1}
            title="治疗医生"
            data={doctorList}
            value={doctor}
            onOk={(v) => getDoctorDay(v)} 
          >
            <Item arrow="horizontal"><Flex>治疗医生  <b style={{color:'red',marginTop:'-10px'}}>*</b></Flex></Item>
          </Picker>
        ):''}

        {department == 'DE0012' && (
            <Picker data={instrumentList} cols={1}
                value={instrument} onOk={v=>{setInstrument(v)}}>
              <Item arrow="horizontal">治疗仪器</Item>
            </Picker>
        )}
        

        {dailyRotation ?(<InputItem type='string' disabled value={doctorName}  
          moneyKeyboardAlign='right' className="input-css">治疗医生
        </InputItem>):''}
        

        {doctorDayShow && !dailyRotation && doctorShow ? 
          <Item   
            extra={
              <div style={{color:'#6495ED'}}>查看手术</div>
            }
            onClick={() => operationSearch()}
          >手术
          </Item>
          : ''
        }
        {!dailyRotation && doctorShow ? (
          <Picker
            cols={1}
            title="其他医生"
            data={doctorList}
            value={doctor2}
            onOk={v => setDoctor2(v)} 
          >
            <Item arrow="horizontal">其他医生</Item>
          </Picker>
        ):''}
        {!dailyRotation && (<DatePicker mode="date" value={date} extra='请选择'
            minDate={_now} onOk={(d) => getDuration(d)}>
            <Item arrow="horizontal"><Flex>治疗日期  <b style={{color:'red',marginTop:'-10px'}}>*</b></Flex></Item>
          </DatePicker>
        )}
        
        {dailyRotation &&(<InputItem type='string' disabled value={date}  
          moneyKeyboardAlign='right' className="input-css">治疗日期
        </InputItem>)}
        
        {timeDataListShow && !dailyRotation && department=="DE0011" ? 
          <div style={{paddingRight:'15px',marginBottom:'5px'}}>
            <Flex className="time-box-title">
              <p>选择治疗时间：</p>
              <span>点击红色可约选择时间</span>
            </Flex>
            {timeDataList.map((item,index) => ( 
              <div className={active==index?'time-width-style-active time-width-style':'time-width-style'}>
                <Flex onClick={() => item.tipsvalue>0?timeBtnClick(item,index):''}>
                  <span className="time-style" style={{"fontSize":"16px"}}>{item.begin}-{item.end}</span>
                  <button className="btn-style" 
                    disabled={item.tipsvalue>0?false:true} 
                    style={item.tipsvalue>0?{backgroundColor:'#e60012'}:(item.tipsvalue==-1?{backgroundColor:'#1b1b1b'}:{backgroundColor:'#a0a0a0'})}
                    
                  >{item.tips}</button>
                </Flex>
              </div> 
            ))}
            
            <div className="clear"></div>
          </div>
        : ''}
       

       

        {department =="DE0011"?(
           <div className="time-style-disbled">
           <DatePicker mode="time" disabled value={time2}
           
             nowTimeStamp={nowTimeStamp}
             onChange={d => {
               setTime2(d);
               let time2Num = new Date(d).getTime()
               let time3Num = new Date(time3).getTime()
               if (Number(time2Num) > Number(time3Num)) {
                 setTime3(d)
                 setBookingTime(0)
               } else { 
                 setBookingTime(new Date(Number(time3Num) - Number(time2Num))/(1000*60))
               }
 
             }
 
             }>
             <Item arrow="horizontal">开始时间</Item>
           </DatePicker>
           <DatePicker mode="time" disabled value={time3}
             nowTimeStamp={nowTimeStamp} minDate={time2} onChange={d => {
               setTime3(d)
               let time2Num = new Date(time2).getTime()
               let time3Num = new Date(d).getTime()
               setBookingTime(new Date(Number(time3Num) - Number(time2Num))/(1000*60))
             }}>
             <Item arrow="horizontal">结束时间</Item>
           </DatePicker>
         </div>
 
 
        ):null}




{
           (department =='DE0012' || department =='DE0013' || department =='DE0014' || department =='DE0015' )?(
              <DatePicker  mode="time" value={timeView1}
             
              onChange={d => {
                setTimeView1(d);
                let time1Num = new Date(d).getTime()
                let time2Num = new Date(timeView2).getTime()
                if (Number(time1Num) > Number(time2Num)) {
                  setTimeView2(d)
                }
              } 
              }>
              <Item arrow="horizontal">开始时间</Item>
            </DatePicker>
           ):null

        }

{
           (department =='DE0012' || department =='DE0013' || department =='DE0014' || department =='DE0015' )?(
            <DatePicker  mode="time" value={timeView2}
             minDate={timeView1} onChange={d => {
              setTimeView2(d)
              
            }}>
            <Item arrow="horizontal">结束时间</Item>
          </DatePicker>
           ):null

        }






 
       {
          department=="DE0011"?(
            <InputItem type='number' value={bookingTime}
            onBlur={() => { setTimeBlur(true) }}
            onChange={v => { setTimeBlur(false); setBookingTime(v) }}
            moneyKeyboardAlign='right' extra="分钟" className="input-css" disabled>治疗时长</InputItem>
  
          ):null

       }

        

      </List>

      <List className='g-p5-10 g-bg-f g-bdrs12'>
        <TextareaItem value={mark} rows={5} count={100} onChange={setMark} className="input-css" placeholder='请输入备注信息...' />
      </List>
      <Flex>
        <Flex.Item><Btn type='warning' onClick={returnNextStep} className="edut2-operation-button">返回上一步</Btn></Flex.Item>
        <Flex.Item><Btn type='primary' onClick={submit} className="edut2-operation-button">提交保存</Btn></Flex.Item>
      </Flex>


      <Modal popup className='v-yueyu-edit2'
        visible={time1}
        animationType='slide-up'
        onClose={() => { setTime1(false) }}>
        <div className='v-time1 g-flex'>
          {timeList.map((i, idx) => (
            <div className='v-time1-item g-l g-ta-c g-box'
              onClick={() => { showSelectTime(i) }} key={idx} >
              <p className='v-time1-item2 g-r' style={{ background: i.isBlank ? '#108ee9' : '#A0A0A0' }}>
                {i.isBlank ? '预约' : '约满'}
              </p>
              {dateFormat(i._start, 'hh:mm')}-{dateFormat(i._end, 'hh:mm')}
            </div>
          ))}
        </div>
      </Modal>
      {timeIdx._show ? <DatePicker visible={timeIdx.show} mode="time" value={date}
        minDate={timeIdx.minDate} maxDate={timeIdx.maxDate}
        onOk={selectTime} onDismiss={selectTime} /> : null}

      {/* 右边弹出 */}
      {doctorDayListShow ? <Drawer
        className="my-drawer"
        style={{ minHeight: document.documentElement.clientHeight, position: 'fixed' }}
        enableDragHandle
        contentStyle={{ color: '#A6A6A6', textAlign: 'center', paddingTop: 42 }}
        sidebar={
          <div className="yuyue-edit2-doctor-box">
            <Calendar
              onDateClick={(d) => onDateClick(d)}
              showType={'month'}
              markDates={[]}
              markType="dot"
              currentDate={dateValue}
            />

            <div className="doctor-box-accordion">
              <div className="doctor-box-accordion-title">{doctorTimeTitle}</div>
              {doctorListData.length > 0 ? doctorListData.map((item, idx) => (
                <Card>
                  <Card.Body>
                    <div className="edit-card">
                      <h1>时间：{item.sch_date} {item.begin_time} ~ {item.end_time}</h1>
                      <p>手术：<span>{showhtml(item.trnames)}</span></p>
                    </div>
                  </Card.Body>
                  <Card.Footer content={<span>麻醉类型：{item.hocusTypeName}</span>} extra={<div>时长：{item.estimate_time}分钟</div>} />
                </Card>))
                : ''}

            </div>
          </div>

        }
        open={doctorDayListShow}
        onOpenChange={() => onOpenChange()}
      >
      </Drawer>
        : ''}
    </div>
  )

}

export default Edit2;
